home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / tools / classdoc.lha / classdoc / diagram.H < prev    next >
C/C++ Source or Header  |  1993-08-08  |  3KB  |  117 lines

  1. // Diagram is a class for drawing multiple plots in InterViews.
  2. // The axes of a diagram may be provided with tic marks or a grid.
  3. // The spacing between tic mark labels is determined automatically.
  4. //
  5. // Note that the diagram is not automatically redrawn at every change
  6. // to the plots, in particular not when points are added to the plots.
  7. // Method Draw() will redraw the diagram.
  8. //
  9. // Author: Dag Bruck, Department of Automatic Control, Lund Institute of
  10. // Technology, Box 118, S-221 00 Lund, Sweden.
  11. // Last revision: 1989-04-18.
  12.  
  13.  
  14. #ifndef DIAGRAM_H
  15. #define DIAGRAM_H
  16.  
  17.  
  18. #include <InterViews/interactor.h>
  19.  
  20.  
  21. class PlotRep;
  22.  
  23.  
  24. class Diagram : public Interactor {
  25. public:
  26.   Diagram(const char* heading = nil);
  27.   Diagram(const char* heading, Coord width, Coord height);
  28.   // Creates new Diagram; default dimension 12x8 cm. The heading is stored
  29.   // as the instance name, and can be accessed with method GetInstance().
  30.  
  31.   void SetHeading(const char *);
  32.   // Sets new heading (cannot be nil).
  33.  
  34.   virtual void Limits(float xlow, float xhigh, float ylow, float yhigh);
  35.   // Defines lower and upper limits of the plot area.  The initial plot
  36.   // area ranges from (0, 0) to (1, 1).
  37.   // Plots are scaled to fit available space.
  38.  
  39.   virtual void Tic(float xstart, float xinc, float ystart, float yinc);
  40.   // Determines position of tic marks on axes.  An increment of 0
  41.   // means that the axis is not labeled.  Initially, no tic marks are shown.
  42.  
  43.   virtual void Grid(boolean);
  44.   // Controls drawing of grid.
  45.  
  46.   virtual void Begin(int size = 200, Painter* = nil);
  47.   // Starts a new plot in this diagram, accepting maximum `size' points.
  48.   
  49.   virtual void Plot(float x, float y);
  50.   // Adds point to "current" plot.  The diagram is not automatically
  51.   // redrawn; use method Draw().
  52.  
  53.   virtual void Polyline(int n, float x[], float y[], Painter* = nil);
  54.   // Defines new plot with given contents.  The diagram is not redrawn.
  55.  
  56.   void Redraw(Coord, Coord, Coord, Coord);
  57.   void Reconfig();
  58.   void Resize();
  59.   // Routines declared in class Interactor.
  60.   
  61. protected:
  62.   float xll, xul, yll, yul;
  63.   // Upper and lower limits of plot.
  64.   
  65.   float xscale, yscale;
  66.   Coord xoffset, yoffset;
  67.   // For transforming user's coordinates to screen coordinates.
  68.  
  69.   float xstart, xinc, ystart, yinc;
  70.   // Controls position of tic marks.
  71.  
  72.   float xnumstart, xnuminc, ynumstart, ynuminc;
  73.   // Controls position of tic mark labels.
  74.   
  75.   PlotRep* first;
  76.   // List of plotted curves.
  77.  
  78.   char* labelformat;
  79.   // Printf(3) format string used for tic mark labels.
  80.   // The initial value is "%.4G".
  81.  
  82.   boolean grid;
  83.   // Draw grid or not?
  84.  
  85.   Coord Xmap(float), Ymap(float);
  86.   // Maps user coordinate to screen coordinate used by InterViews.
  87.  
  88.   Coord NumWidth(float);
  89.   // Returns width of number using label format string.
  90.  
  91.   Coord NumIntWidth(float);
  92.   // Returns width of integer part of number using label format string.
  93.  
  94.   virtual void PlotArea();
  95.   // Computes scale and offset of plot area, taking into account
  96.   // space for labels and axes tics. Increments between labeled tic marks
  97.   // are also calculated.
  98.   
  99.   virtual void DrawAxes();
  100.   // Draws axes and heading of diagram.
  101.  
  102. private:
  103.   void Init(const char*);
  104.   // Initializes of Diagram object.
  105. };
  106.  
  107.  
  108. inline Coord Diagram :: Xmap(float x)
  109.   { return Coord((x - xll) * xscale) + xoffset; }
  110.  
  111.  
  112. inline Coord Diagram :: Ymap(float y)
  113.   { return Coord((y - yll) * yscale) + yoffset; }
  114.  
  115.  
  116. #endif
  117.